package com.minshenglife.zanzan.web.weixin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.minshenglife.zanzan.pub.menubtn.MenuBtn;
import com.minshenglife.zanzan.pub.message.WXRespMessage;
import com.minshenglife.zanzan.pub.utils.WXKeys;
import com.minshenglife.zanzan.web.weixin.service.EMOWXBaseServcie;
import com.minshenglife.zanzan.web.weixin.service.WXAccTokenService;
import com.minshenglife.zanzan.web.weixin.service.WXBaseService;
import com.nationsky.pub.utils.GsonUtils;

/**
 * 菜单控制器
 * @author jianghaibo
 *
 */
@Controller
@RequestMapping("/emomenu")
public class EMOMenuController {
	Logger log = LoggerFactory.getLogger(EMOMenuController.class);
	@Resource
	WXAccTokenService tokenService;
	
	@RequestMapping("/createMenu.do")
	public void createMenu(HttpServletRequest request,HttpServletResponse response){
		//创建点击菜单返回图文消息的菜单
		createHasPicMsgMenu();
	}
	

	/**
	 * 创建点击菜单返回图文消息的菜单
	 */
	public void createHasPicMsgMenu() {
		Map<String,Object> map=new HashMap<String,Object>();
		List<Object> btnList=new ArrayList<Object>();
		List<MenuBtn> sub_btnList1=new ArrayList<MenuBtn>();
		List<MenuBtn> sub_btnList2=new ArrayList<MenuBtn>();
		List<MenuBtn> sub_btnList3=new ArrayList<MenuBtn>();
		btnList.add(new MenuBtn("总裁动态",sub_btnList1));
		btnList.add(new MenuBtn("总裁互动",sub_btnList2));
		btnList.add(new MenuBtn("总裁推荐",sub_btnList3));
//		
		String action="/emocore/toPageDoor.do";
		String urlHeader=WXKeys.WX_BASEURL+action+"?key=";
		
		sub_btnList1.add(new MenuBtn(MenuBtn.CLICK,"调研讲话",WXKeys.WX_EMO_BTN_MENU_SPEAK));
		sub_btnList1.add(new MenuBtn(MenuBtn.CLICK,"工作动态",WXKeys.WX_EMO_BTN_MENU_DYNAMIC));
//		
		sub_btnList2.add(new MenuBtn(MenuBtn.CLICK,"问题信箱",WXKeys.WX_EMO_BTN_MENU_EMAIL));
		sub_btnList2.add(new MenuBtn(MenuBtn.CLICK,"建议民生",WXKeys.WX_EMO_BTN_MENU_SUGGEST));
//		
		sub_btnList3.add(new MenuBtn(MenuBtn.VIEW,"公司热点",urlHeader + WXKeys.WX_EMO_BTN_MENU_HOT));
		sub_btnList3.add(new MenuBtn(MenuBtn.CLICK,"行业前沿",WXKeys.WX_EMO_BTN_MENU_FOREFRONT));
		sub_btnList3.add(new MenuBtn(MenuBtn.VIEW,"精彩民生",urlHeader + WXKeys.WX_EMO_BTN_MENU_WONDERFUL));
		
		map.put("button", btnList);
		
		try {
//			String token = EMOWXBaseServcie.getWXAccessToken();
//			WXRespMessage respMessage=WXBaseService.createMenu(map,token);
			WXRespMessage respMessage=WXBaseService.createMenu(map,tokenService.getEMOWXAccToken());
			log.info("==========="+respMessage.getErrcode());
			System.out.println("==========="+respMessage.getErrcode());
			if("0".equals(respMessage.getErrcode())){
				log.info("菜单创建成功");
			}else{
				log.info("菜单创建失败，错误信息："+respMessage.getErrmsg());
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
	}
	
	
	public static void main(String[] sadf){
		Map<String,Object> map=new HashMap<String,Object>();
		List<Object> btnList=new ArrayList<Object>();
		List<MenuBtn> sub_btnList1=new ArrayList<MenuBtn>();
		List<MenuBtn> sub_btnList2=new ArrayList<MenuBtn>();
		List<MenuBtn> sub_btnList3=new ArrayList<MenuBtn>();
		btnList.add(new MenuBtn("排行榜",sub_btnList1));
		btnList.add(new MenuBtn("我",sub_btnList2));
		btnList.add(new MenuBtn("更多",sub_btnList3));
		
		String action="/core/toPageDoor.do";
		String urlHeader=WXKeys.WX_BASEURL+action+"?key=";
		sub_btnList1.add(new MenuBtn(MenuBtn.VIEW,"红花榜",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_REDRANKING));
		sub_btnList1.add(new MenuBtn(MenuBtn.VIEW,"送花榜",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_SENDRANKING));
		sub_btnList1.add(new MenuBtn(MenuBtn.VIEW,"进步榜",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_PROGRESSRANKING));
		sub_btnList1.add(new MenuBtn(MenuBtn.VIEW,"积分榜",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_INTEGRALRANKING));
		
		sub_btnList2.add(new MenuBtn(MenuBtn.VIEW,"我的红花",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_MYREDFLOWER));
		sub_btnList2.add(new MenuBtn(MenuBtn.VIEW,"我的积分",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_MYTEGRAL));
		sub_btnList2.add(new MenuBtn(MenuBtn.VIEW,"我的吐槽",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_MYTOCAO));
		sub_btnList2.add(new MenuBtn(MenuBtn.VIEW,"我的评论",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_MYREVIEW));
		sub_btnList2.add(new MenuBtn(MenuBtn.VIEW,"个人信息",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_MYINFO));
		
		sub_btnList3.add(new MenuBtn(MenuBtn.VIEW,"游戏大厅",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_GAME));
		sub_btnList3.add(new MenuBtn(MenuBtn.VIEW,"吐槽版",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_TUCAO));
		sub_btnList3.add(new MenuBtn(MenuBtn.VIEW,"新鲜事",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_NEWTHING));
		sub_btnList3.add(new MenuBtn(MenuBtn.VIEW,"帮助",urlHeader+WXKeys.WX_ZZMSR_BTN_MENU_HELPREPLAY));
		
		map.put("button", btnList);
		
		String json=GsonUtils.toGson(map);
		json=json.replace("\\u003d", "=");
		System.out.println(json);
	}

	
}
